package com.cyq.dascma.handler.valida.impl;

import com.cyq.dascma.constant.ValidaEnum;
import com.cyq.dascma.entity.Schedule;
import com.cyq.dascma.exception.ServiceException;
import com.cyq.dascma.handler.valida.Valida;
import com.cyq.dascma.result.ResultGenerator;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * dingwen
 * 2021/4/4 17:59
 **/
public class ScheduleValidaImpl implements Valida<Schedule> {
    @Override
    public void valida(ValidaEnum validaEnum, Schedule schedule) {
        if (ObjectUtils.isEmpty(schedule)) {
            throw new ServiceException(ResultGenerator.genFailureResult("schedule不能为空").setCode(400));
        }
        switch (validaEnum) {
            case ADD:
                if (!StringUtils.hasText(schedule.getScheduleId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("scheduleId不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getClazzId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("上课班级编号不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getClazzId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("授课教师编号不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getCourseId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("课程编号不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getScheduleTimeStart().toString())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("上课开始时间不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getScheduleTimeEnd().toString())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("上课结束时间不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getScheduleYear())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("学年不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getScheduleTimeEnd().toString())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("学期不能为空").setCode(400));
                }

                break;
            case MODIFY:
                if (!StringUtils.hasText(schedule.getScheduleId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("scheduleId不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getClazzId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("上课班级编号不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getCourseId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("课程编号不能为空").setCode(400));
                }
                if (!StringUtils.hasText(schedule.getClazzId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("授课教师编号不能为空").setCode(400));
                }
                break;
        }
    }
}
